package com.newtouch.avmarketing.api.controller;

import com.newtouch.avmarketing.api.entity.Signature;
import com.newtouch.avmarketing.api.service.SignatureService;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.model.Result;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.model.ResultCodes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "09 双录节点：签名图片查询")
@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/api/signature")
public class SignatureController {

    @Autowired
    private SignatureService signatureService;

    @ApiOperation(value = "签名保存")
    @PostMapping("/saveSignature")
    public Result saveSignature(@RequestBody Signature signature){
        try {
            signatureService.saveOrUpdateSignature(signature);
            return Result.of(ResultCodes.SUCCESS_CODE,"保存成功");
        }catch (Exception e ){
            e.printStackTrace();
        }
        return Result.of(ResultCodes.ERROR_CODE,"保存失败");
    }

    @ApiOperation(value = "客户端签名查询")
    @PostMapping("/findSignature")
    public Result findByPolicyCodeAndPageName(@ApiParam("policyCode") @RequestParam String policyCode
            ,@ApiParam("pageName") @RequestParam String pageName){
        Signature signature = signatureService.findByPolicyCodeAndPageName(policyCode, pageName);
        try {
            if (null != signature){
                return Result.of(ResultCodes.SUCCESS_CODE,"查询成功",signature);
            }else {
                return Result.of(ResultCodes.ERROR_CODE,"查询失败");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.of(ResultCodes.ERROR_CODE,"查询失败");
    }
}
